package com.anolesoft.yr.mbus.cont.entity;

import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 合同条款基础表
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "cont_item")
public class ContItem implements Serializable {
    /**
     * 主键
     */
    @TableId(value = "objuid", type = IdType.INPUT)
    private String objuid;

    /**
     * 父级
     */
    @TableField(value = "parent_uid")
    private String parentUid;

    /**
     * 类型
     */
    @TableField(value = "item_type")
    private String itemType;

    /**
     * 序号
     */
    @TableField(value = "order_no")
    private Byte orderNo;

    /**
     * 内容
     */
    @TableField(value = "item_content")
    private String itemContent;

    private List<ContItem> contItems;
    /**
     * 内容种类
     */
    @TableField(value = "content_type")
    private String contentType;

    private static final long serialVersionUID = 1L;

    public static final String COL_OBJUID = "objuid";

    public static final String COL_PARENT_UID = "parent_uid";

    public static final String COL_ITEM_TYPE = "item_type";

    public static final String COL_ORDER_NO = "order_no";

    public static final String COL_ITEM_CONTENT = "item_content";

    public static final String COL_CONTENT_TYPE = "content_type";

    public JSONObject toJson() {
        String s = JSONObject.toJSONString(this);
        JSONObject json = JSONObject.parseObject(s);
        JSONArray array = new JSONArray();
        this.contItems.forEach(a -> {
            array.add(a.toJson());
        });
        json.put("child", array);
        return json;
    }
}